package com.woniuxy.stage3demo.controller.gy;

import com.github.pagehelper.PageInfo;
import com.woniuxy.stage3demo.bean.gy.OverdueBean;
import com.woniuxy.stage3demo.bean.gy.OverdueIm;
import com.woniuxy.stage3demo.bean.gy.UserDemo;
import com.woniuxy.stage3demo.pageHelper.PageRequest;
import com.woniuxy.stage3demo.pageHelper.TableResult;
import com.woniuxy.stage3demo.service.gy.OverdueOrderService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ：xxx
 * @description：TODO
 * @date ：2020/12/15 14:38
 */
@RequestMapping("rpr")
@RestController
public class repaymentReminderController {
    @Resource
    private OverdueOrderService overdueOrderService;
    //查询所有未还完的人信息
    @GetMapping(value = "/page",produces = {"application/json;charset=utf-8"})
    public TableResult findPage(PageRequest pageRequest, UserDemo userDemo){
        PageInfo<OverdueBean> byStatus = overdueOrderService.findByStatus(pageRequest.getPageNum(), pageRequest.getLimit(), userDemo);
        System.out.println(byStatus);
        long total = byStatus.getTotal();
        List<OverdueBean> rows = byStatus.getList();
        TableResult tr = new TableResult<>();
        tr.setTotal(total);
        tr.setRows(rows);
        return tr;
    }

    @GetMapping(value = "/findAll",produces = {"application/json;charset=utf-8"})
    public OverdueIm findAll(){
        int countMonth = overdueOrderService.findCount();
        int countYear = overdueOrderService.findCountYear();
        List<Long> countMoney = overdueOrderService.findCountMoney();
        final long[] countNum1 = {0};
        countMoney.forEach(e->{
            countNum1[0] = countNum1[0] +e;
        });
        List<Long> countMoneyYear = overdueOrderService.findCountMoneyYear();
        final long[] countNum2 = {0};
        countMoneyYear.forEach(e->{
            countNum2[0]=countNum2[0]+e;
        });
        OverdueIm oi = new OverdueIm();
        oi.setCountMonth(countMonth);
        oi.setCountYear(countYear);
        oi.setCountMonthCount(countNum1[0]);
        oi.setCountYearCount(countNum2[0]);
        System.out.println(oi);
        return oi;
    }
}
